package cn.tedu.account.tx;

import cn.tedu.account.entity.TxAccountMessage;
import cn.tedu.account.service.AccountService;
import cn.tedu.account.util.JsonUtil;
import com.fasterxml.jackson.core.type.TypeReference;// jackson包
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;

public class TxConsumer implements RocketMQListener<String> {
    @Autowired
    private AccountService accountService;
    @Override
    public void onMessage(String s) {
        TxAccountMessage txA = JsonUtil.from(s, new TypeReference<TxAccountMessage>() {
        });
        accountService.decrease(txA.getUserId(),txA.getMoney());

    } //实现消息监听，收到消息后完成扣减金额业务

}
